package customer_manage_function_implementation;

import java.util.LinkedList;

import customer_manage_database.Customer;




public class UpdateCustomer {
	/*
	 *Update客户信息 
	 */
	//Update Customer
	public LinkedList<Customer> UpdateCustomer(String[] str,LinkedList<Customer> lList){
		int id=Integer.parseInt(str[0].substring(str[0].indexOf(":")+1));
		Customer customer=lList.get(id-1);
		for (int i = 1; i < str.length; i++) {
			switch (str[i].substring(0,str[i].indexOf(":"))) {    //得到每个数组传递的是什么信息
			case "name":
				String sName=str[i].substring(str[i].indexOf(":")+1);
				if (sName.length()!=0) {             //如果name后面的参数内容有效，则赋给要Update的customer
					customer.setName(sName);		
				}
				break;
			case "sex":
				String sSex=str[i].substring(str[i].indexOf(":")+1);
				if (sSex.length()!=0) {
					int iSex=Integer.parseInt(sSex);
					customer.setSex(iSex);
				}
			    break;
			case "birthday":
				String sBirthday=str[i].substring(str[i].indexOf(":")+1);
				if (sBirthday.length()!=0) {
					customer.setBirthday(sBirthday);
				}
				break;
			case "address":
				String sAddress=str[i].substring(str[i].indexOf(":")+1);
				if (sAddress.length()!=0) {
					customer.setAddress(sAddress);
				}
				break;
			case "call":
				String sCall=str[i].substring(str[i].indexOf(":")+1);
				if (sCall.length()!=0) {
					customer.setCall(sCall);
				}
				break;

			default:
				break;
			}					
		}
		return lList;
		
	}
	//根据解析出的ID在list找到对应customer
	public int getCustomerById(int id,LinkedList<Customer> lList) {
		int i = 0;
		for (; i < lList.size(); i++) {
			if (lList.get(i).getID()==id) {
				break;
			}
			else{
				i=-1;
			}				
		}
		return i;		
		
	}
		
	

}
